package com.onec.service.channel.service.channel.base;

import com.onec.service.api.dto.request.channel.ChannelMerchantReq;
import com.onec.service.api.dto.response.channel.ChannelMerchantResp;
import com.onec.service.api.enums.ProductEnum;
import com.onec.service.api.enums.StatusEnum;
import com.onec.service.channel.entity.ChannelInfo;
import com.onec.service.channel.entity.ChannelMerchant;
import com.onec.service.channel.service.ChannelInfoService;
import com.onec.service.channel.service.ChannelKeyService;
import com.onec.service.channel.service.ChannelMerchantBusinessService;
import com.onec.service.channel.service.ChannelMerchantService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import java.math.RoundingMode;

/**
 * 上游通道通用类默认实现方法
 *
 * @author ONEC
 */
public abstract class BaseChannelMerchantDefaultService implements BaseChannelMerchantService {

    @Autowired
    protected ChannelMerchantService channelMerchantService;
    @Autowired
    protected ChannelMerchantBusinessService channelMerchantBusinessService;
    @Autowired
    protected ChannelKeyService channelKeyService;
    @Autowired
    protected ChannelInfoService channelInfoService;


    // 实现默认方法：
    @Override
    public RoundingMode getRoundingMode() {
        return null;
    }

    @Override
    public boolean needRegister() {
        return false;
    }

    @Override
    public ChannelMerchantResp register(ChannelMerchantReq channelMerchantReq, ChannelInfo channelInfo) {
        return null;
    }

    @Override
    public ChannelMerchantResp productOpen(ChannelMerchantReq channelMerchantReq, ChannelInfo channelInfo) {
        return null;
    }


    @Override
    public ChannelMerchantResp updateMerchantSettle(ChannelMerchantReq channelMerchantReq, ChannelInfo channelInfo) {
        return null;
    }


    @Override
    public ChannelMerchantResp notifyMerchantApi(HttpServletRequest request) {
        return null;
    }

    @Override
    public ChannelMerchantResp notifySettleApi(HttpServletRequest request) {
        return null;
    }

    @Override
    public boolean checkMerchantTradeValue(ChannelMerchantReq merchantInfoParam, ChannelInfo channelInfo) {
        return false;
    }


    @Override
    public void afterPropertiesSet() {

    }

    /**
     * 通道返回成功，处理成功订单.
     * 商户注册等：
     *
     * @param
     * @return
     */
    protected ChannelMerchant updateMerchantChannel(long channelId, ProductEnum productEnum, StatusEnum statusEnum,
                                                    String merchantNo, String channelMerchantNo, String message) {
        ChannelMerchant channelMerchant = channelMerchantService
                .findByChannelIdProductMerchantNo(channelId, merchantNo, productEnum);
        channelMerchant.setStatus(statusEnum);
        channelMerchant.setChannelMerchantNo(channelMerchantNo);
        channelMerchant.setRemarks(message);
        return channelMerchantService.updateChannelMerchant(channelMerchant);
    }

}
